package com.tadpole.music.view.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.tadpole.music.R;
import com.tadpole.music.bean.home.GoClockInBean;
import com.tadpole.music.utils.DateUtils;

import razerdp.basepopup.BasePopupWindow;

/**
 * 打卡成功
 * Created By 孙岩
 * on 2020/12/9
 */
public class ClockInPopSuccess extends BasePopupWindow implements View.OnClickListener {
    //前往答题
    private TextView tvGo;
    //打卡天数
    private TextView tvCount;
    //头像
    private NiceImageView ivImage;
    //姓名
    private TextView tvName;
    //年龄
    private TextView tvAge;
    //日期
    private TextView tvTime;
    //内容
    private TextView tvContent;
    //二维码
    private ImageView ivCode;
    //分享好友
    private TextView tvShare;
    //关闭
    private ImageView ivClose;
    private LinearLayout llBg;
    private IClockInMode iClockInMode;

    public ClockInPopSuccess(Context context, GoClockInBean.DataBean bean) {
        super(context);
        tvGo = (TextView) findViewById(R.id.tvGo);
        llBg = (LinearLayout) findViewById(R.id.llBg);
        tvCount = (TextView) findViewById(R.id.tvCount);
        ivImage = (NiceImageView) findViewById(R.id.ivImage);
        tvName = (TextView) findViewById(R.id.tvName);
        tvAge = (TextView) findViewById(R.id.tvAge);
        tvTime = (TextView) findViewById(R.id.tvTime);
        tvContent = (TextView) findViewById(R.id.tvContent);
        ivCode = (ImageView) findViewById(R.id.ivCode);
        tvShare = (TextView) findViewById(R.id.tvShare);
        ivClose = (ImageView) findViewById(R.id.ivClose);
        tvGo.setOnClickListener(this);
        tvShare.setOnClickListener(this);
        ivClose.setOnClickListener(this);
        setData(context,bean);
    }

    //设置数据
    @SuppressLint("SetTextI18n")
    private void setData(Context context,GoClockInBean.DataBean bean){
        tvCount.setText(bean.getSign_data().getTotal_sign_days()+"");
        RequestOptions requestOptions = new RequestOptions()
                .placeholder(R.mipmap.app_icon)
                .error(R.mipmap.app_icon)
                .priority(Priority.HIGH)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(context).load( bean.getUser().getAvatar()).apply(requestOptions).into(ivImage);
        tvName.setText(bean.getUser().getNickname());

        if(bean.getUser().getAge()==0){
            tvAge.setVisibility(View.GONE);
        }else{
            tvAge.setVisibility(View.VISIBLE);
            tvAge.setText(bean.getUser().getAge()+"岁");
        }

        tvTime.setText(DateUtils.getCurrentYearAndMonthAndDay());

        Glide.with(context).load(bean.getErweima()).apply(requestOptions).into(ivCode);

        if(bean.getSayings().getContent().equals("")&&bean.getSayings().getAuthor().equals("")){
            tvContent.setVisibility(View.INVISIBLE);
        }else{
            tvContent.setVisibility(View.VISIBLE);
            tvContent.setText(bean.getSayings().getContent()+"—————"+bean.getSayings().getAuthor());
        }
    }

    @Override
    protected Animation initShowAnimation() {
        return null;
    }

    @Override
    public View getClickToDismissView() {
        return getPopupWindowView();
    }

    @Override
    public View onCreatePopupView() {
        return createPopupById(R.layout.pop_clock_in);
    }

    @Override
    public View initAnimaView() {
        return findViewById(R.id.rlSuccess);
    }

    public void setModeListener(IClockInMode iClockInMode) {
        this.iClockInMode = iClockInMode;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tvGo://答题
                iClockInMode.getMode(1,llBg);
                break;
            case R.id.tvShare://分享
                iClockInMode.getMode(2,llBg);
                break;
            case R.id.ivClose://关闭
                dismiss();
                break;
        }
    }

    public interface IClockInMode{
        void getMode(int mode,LinearLayout llBg);
    }
}
